package com.xn.app.muying.adpter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.xn.app.muying.R;
import com.xn.app.muying.activity.ChanJianListActivity;
import com.xn.app.muying.activity.ChanJianXiangQingActivity;
import com.xn.app.muying.bean.ChanJianMessageBean;

import java.util.ArrayList;
import java.util.zip.Inflater;

/**
 * Created by Administrator on 2016/10/29.
 */
public class ChanJianXiangQingAdapter  extends BaseAdapter{

    private  LayoutInflater inflater;
    private Context context;
    private ArrayList<ChanJianMessageBean> list = new ArrayList<ChanJianMessageBean>();

    public  ChanJianXiangQingAdapter(Context context, ArrayList list){
        this.context=context;
        this.list=list;
        inflater= LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        ViewHoler_GridView viewHoler_gridView=new ViewHoler_GridView();

//        if(view==null){
            view=inflater.inflate(R.layout.item_gridview,null);
            viewHoler_gridView.btn_name= (Button) view.findViewById(R.id.item_gridview_btn);
//            view.setTag(viewHoler_gridView);
//        }else{
//            viewHoler_gridView= (ViewHoler_GridView) view.getTag();
//        }
        ChanJianXiangQingActivity.tv_info.setText(list.get(0).getExplain());
        ChanJianXiangQingActivity.tv_message.setText(list.get(0).getTip());
        viewHoler_gridView.btn_name.setText(list.get(i).getName());

//        tv_optionalItems.setBackgroundResource(R.drawable.button_red_kepu2);
//        tv_requiredItems.setBackgroundResource(R.drawable.button_white_kepu1);


        viewHoler_gridView.btn_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ChanJianXiangQingActivity.tv_info.setText(list.get(i).getExplain());
                ChanJianXiangQingActivity.tv_message.setText(list.get(i).getTip());
            }
        });


        return view;
    }


    class ViewHoler_GridView{
        Button btn_name;
    }
}
